var ytplidx = 1, ytplpls = [], ytpl_ajaxContinue = true, max_results = 10;
function loadPlaylists (auth) {
  var max_result = 10, ytplidx = 1, ytplpls = [], ytpl_ajaxContinue = true;
  var token = auth.getAccessToken();
  while (true) {
    try {
      $.ajax({
        'url':  'https://gdata.youtube.com/feeds/api/users/default/playlists?v=2&alt=json&oauth_token='+token+'&max-results='+max_results+'&start-index='+ytplidx,
        'dataType': 'json',
        'async':    false,
        statusCode: {
          401:  function(){throw "oautherror"; } // token error
        },
        'headers':  {
          'Authorization':  'OAuth ' + token
        },
        ajaxContinue: ytpl_ajaxContinue,
        success:    function(obj) {
          ytpl_ajaxContinue = this.ajaxContinue;
          if (obj.feed.entry == undefined || obj.feed.entry.length == 0){
            ytpl_ajaxContinue = false;
            return;
          }
          for (var i in obj.feed.entry) {
            ytplpls.push({
              'title':    obj.feed.entry[i].title["$t"],
              'apiuri':   obj.feed.entry[i].content["src"],
              'num':      obj.feed.entry[i].yt$countHint["$t"]
            });
            if (ytplpls.length == parseInt(obj.feed.openSearch$totalResults["$t"], 10)) {
              ytpl_ajaxContinue = false;
              break;
            }
          }
        }
      });
      if (ytpl_ajaxContinue == false) {
        throw "nonext";
        break;
      }
      ytplidx += 7;
    } catch (err) {
      if (err.toLowerCase() != "nonext") {
        alert(err);
      }
      break;
    }
  }
  return ytplpls;
}